package com.yunhe.authority.controller.appPush;

import com.yunhe.authority.service.app.AppPushInfoService;
import com.yunhe.common.model.ResultObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author zhengbo
 * @date 2021/11/11 17:24
 */

@Api(value = "AppPush", description = "App推送", tags = {"App推送"})
@RestController
@RequestMapping("/appPush")
public class AppPushController {

    @Autowired
    private AppPushInfoService appPushInfoService;

    /**
     * 根据用户Ids推送消息
     * @param userIds 用户Ids
     * @param notificationTitle 通知标题
     * @param msgContent 消息内容
     * @param extras 额外字段
     */
    @ApiOperation("根据用户Ids推送消息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userIds", value = "用户Ids", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "notificationTitle", value = "通知标题", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "msgContent", value = "消息内容", required = true, dataType = "String", paramType = "query")
    })
    @RequestMapping(value = "/pushMessageByUserIds", method = RequestMethod.POST)
    public ResponseEntity<ResultObject> pushMessageByUserIds(@RequestParam("userIds") String userIds,
                                                      @RequestParam("notificationTitle") String notificationTitle,
                                                      @RequestParam("msgContent") String msgContent,
                                                      @RequestBody() Map<String, String> extras) {

        appPushInfoService.pushMessageToUserList(userIds, notificationTitle, notificationTitle, msgContent, extras);

        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    /**
     * 根据虚拟园区id推送消息
     * @param stationId 虚拟园区ID
     * @param notificationTitle 通知标题
     * @param msgContent 消息内容
     * @param extras 额外字段
     */
    @ApiOperation("根据用户Ids推送消息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationId", value = "虚拟园区ID", required = true, dataType = "Long", paramType = "query"),
            @ApiImplicitParam(name = "notificationTitle", value = "通知标题", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "msgContent", value = "消息内容", required = true, dataType = "String", paramType = "query")
    })
    @RequestMapping(value = "/pushMessageByStationId", method = RequestMethod.POST)
    public ResponseEntity<ResultObject> pushMessageByStationId(@RequestParam("stationId") Long stationId,
                                                      @RequestParam("notificationTitle") String notificationTitle,
                                                      @RequestParam("msgContent") String msgContent,
                                                      @RequestBody() Map<String, String> extras) {

        appPushInfoService.pushMessageToStationUser(stationId, notificationTitle, notificationTitle, msgContent, extras);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }
}
